package eu.kleinkoerkamp.apptest.ui.wicket.home;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

import eu.kleinkoerkamp.apptest.domain.TestObject;
import eu.kleinkoerkamp.apptest.service.TestService;

public class HomePage extends WebPage {
	
	@SpringBean
	private TestService m_testService;

	public HomePage(){
		super();
		add(new Label("message", new Model<String>("Wicket running on google app engine :)")));
		
		Collection<TestObject> coll = m_testService.getObjects();
		
		List<TestObject> listObj = new ArrayList<TestObject>();
		listObj.addAll(coll);
		ListView<TestObject> list = new ListView<TestObject>("list", listObj){
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<TestObject> listItem) {
				TestObject obj = listItem.getModelObject();
				listItem.add(new Label("itemText", obj.getId() + " : " + obj.getName()));
			}
			
		};
		add(list);
	}
}
